extends PanelContainer

# 信号
signal slot_selected(slot_index: int)

# 槽位索引
var slot_index: int = 0

# 节点引用
@onready var slot_title = $MarginContainer/VBoxContainer/SlotTitle
@onready var character_info = $MarginContainer/VBoxContainer/CharacterInfo
@onready var time_info = $MarginContainer/VBoxContainer/TimeInfo

# 设置槽位信息
func setup(index: int, slot_info: Dictionary, is_save_mode: bool) -> void:
	slot_index = index
	
	# 更新槽位标题
	slot_title.text = "存档槽位 %d" % (index + 1)
	
	# 更新角色信息
	if slot_info.is_empty():
		character_info.text = "角色：未创建"
		time_info.text = "最后保存：无"
	else:
		character_info.text = "角色：%s\n境界：%s (等级 %d)" % [
			slot_info.player_name,
			slot_info.realm,
			slot_info.level
		]
		time_info.text = "最后保存：%s" % slot_info.timestamp
	
	# 设置样式
	var style = get_theme_stylebox("panel")
	if not slot_info.is_empty():
		style.bg_color = Color(0.2, 0.25, 0.3)
	else:
		style.bg_color = Color(0.15, 0.17, 0.2)
	
	# 设置提示文本
	tooltip_text = "点击%s到槽位 %d" % ["保存" if is_save_mode else "加载", index + 1]

# 鼠标点击事件
func _gui_input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
			emit_signal("slot_selected", slot_index)

# 鼠标悬停效果
func _on_mouse_entered() -> void:
	modulate = Color(1.1, 1.1, 1.1)

# 鼠标离开效果
func _on_mouse_exited() -> void:
	modulate = Color(1.0, 1.0, 1.0)